package com.xiaoqi.api.handle;

import com.xiaoqi.api.exception.ParamException;
import com.xiaoqi.api.utlis.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.servlet.NoHandlerFoundException;

@RestControllerAdvice
/**
 * 步骤：1,加上注解@RestControllerAdvice
 */
public class GlobalExceptionHandler {

    private Logger logger = LoggerFactory.getLogger(GlobalExceptionHandler.class);

    /**
     * 处理传参异常
     * @param paramException
     * @return
     */
    @ExceptionHandler(ParamException.class)
    public Result handleParamException(ParamException paramException){
        paramException.printStackTrace();
        logger.error(paramException.getMessage()); //参数异常
        return Result.failure(paramException.getMessage());
    }

<<<<<<< HEAD
//    //这个方法是如果抛出这个(Exception异常，会执行这个方法
//    @ExceptionHandler(Exception.class)
//    public Result<String> handlerException(Exception exception){
//        Result<String> result = new Result();
//        result.setCode(500);
//        result.setMsg("服务器繁忙！");
//        return result;
//    }
=======
    /**
     * 处理服务器繁忙
     * @param exception
     * @return
     */
    @ExceptionHandler(Exception.class)
    public Result handleException(Exception exception){
        logger.error(exception.getMessage());
        exception.printStackTrace();

        return Result.failure("请稍等,服务器繁忙!......");

    }

>>>>>>> 2be0ca3c385849c7db76761b31c038c7d1424ce8
}
